package com.gufe.controller.user.community;


import com.gufe.dto.communitydto.PostCommentDTO;
import com.gufe.result.Result;
import com.gufe.service.user.community.CommentService;
import com.gufe.vo.communityvo.PostCommentVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/api/user/community/comment")
public class CommentController {

    @Autowired
    private CommentService commentService;

    // 获取帖子对应的评论数据
    @GetMapping()
    public Result getCommentByPostID(@RequestParam Integer postId){
        log.info("获取帖子对应的评论数据...");
        List<PostCommentVO> postComments = commentService.getComments(postId);
        return Result.success(postComments);
    }

    // 新增评论
    @PostMapping()
    public Result addComment(@RequestBody PostCommentDTO postCommentDTO) {
        log.info("新增帖子信息：{}",postCommentDTO);
        commentService.addComment(postCommentDTO);
        return Result.success();
    }
}
